<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>home</title>
<jsp:include page="../common/BaseHead.jsp" />
<script type="text/javascript" src="../../js/JsSvc/unifySvc.js"></script>
<script type="text/javascript" src="../../js/JsSvc/Config.js"></script>
<script type="text/javascript" src="../../media/js/pagination.js"></script>
<script type="text/javascript">
	var app = angular.module('CategoryApp', [ 'ngResource', 'ngMessages', 'unifyModule', 'myPagination' ]);
	app.controller('CategoryController', function($scope, CategorySvc) {
		$scope.formParms = {};
		$scope.queryData = {};
		$scope.Did='';
		$scope.titleMsg='';
		
		var url = location.search;
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
            }
        }
        if(theRequest.categoryType=='0'){
        	$scope.navigationMsg='设备';
        }else{
        	$scope.navigationMsg='周转材料';
        }
        
		/*
		 *分页标签参数配置
		 */
		$scope.paginationConf = {
			currentPage : 1,/*当前页数*/
			totalItems : 1,/*数据总数*/
			pageRecord : 3,/*每页显示多少*/
			pageNum : 10,/*分页标签数量显示*/
			/*
			 * parm1:当前选择页数
			 * parm2:每页显示多少
			 */
			queryList : function(parm1, parm2) {
				$scope.paginationConf.currentPage = parm1;
				$scope.query();
			}
		};

		$scope.query = function() {
			//console.log('查询条件',$scope.queryData);
			$scope.queryData['categoryType']=theRequest.categoryType;
			$scope.queryData['pageNo'] = $scope.paginationConf.currentPage - 1;
			$scope.queryData['pageSize'] = $scope.paginationConf.pageRecord;
			CategorySvc.get($scope.queryData, aSucc, aErr);
			function aSucc(rec) {
				$scope.dataList = rec.data;
				$scope.paginationConf.totalItems = rec.totalElements;
			}
			function aErr(rec) {
			}
		};
		$scope.queryDetail = function() {
			$scope.formParms["id"] = 2;
			CategorySvc.get({
				parm : $scope.formParms.id
			}, $scope.formParms, aSucc, aErr);
			function aSucc(rec) {
				console.log('返回对象', rec);
			}
			function aErr(rec) {
			}
		};

		$scope.openUpdModal = function(obj) {
			$scope.formParms = obj;
			$scope.judge = "upd";
			$scope.titleMsg = $scope.navigationMsg+"类别修改";
			$('#useCategoryId').modal();
		};
		$scope.upd = function() {
			var id=$scope.formParms.id;
			CategorySvc.post({parm : id}, $scope.formParms, aSucc, aErr);
			function aSucc(rec) {
				$('#useCategoryId').modal('hide');
				$.messager.popup(rec.msg);
				$scope.query();
			}
			function aErr(rec) {
			}
		};

		$scope.del=function(obj){
			$scope.Did=obj.id;
			$('#confirmModal').modal();
		};
		$scope.delOk=function(){
			CategorySvc.del({parm:$scope.Did},aSucc,aErr);
			function aSucc(rec){
				$('#confirmModal').modal('hide');
				$.messager.popup(rec.msg);
				$scope.query();
			}
			function aErr(rec){
			}
		};
		$scope.delCancel=function(){
			$('#confirmModal').modal('hide');
		};

		$scope.openAddModal = function() {
			$scope.formParms=theRequest;
			$scope.judge = "add";
			$scope.titleMsg = $scope.navigationMsg+"类别添加";
			$('#useCategoryId').modal();
		};
		$scope.add = function() {
			console.log('获取的添加数据：',$scope.formParms);
			//$scope.formParms['categoryType']=0;
			CategorySvc.put({}, $scope.formParms, aSucc, aErr);
			function aSucc(rec) {
				$('#useCategoryId').modal('hide');
				$.messager.popup(rec.msg);
				$scope.query();
			}
			function aErr(rec) {
			}
		};
		
		$scope.modelCancel=function(){
			$('#useCategoryId').modal('hide');
		};
		
		$scope.categoryState=[{id:'0',value:'禁用'},{id:'1',value:'启用'}];
	});

</script>
</head>
<body ng-app="CategoryApp" ng-controller="CategoryController">
	<nav class="breadcrumb">
		<i class="Hui-iconfont">&#xe67f;</i>
		首页<span class="c-gray en">&gt;</span>档案维护<span class="c-gray en">&gt;</span>{{navigationMsg}}分类管理
	</nav>
	
	<div class="panel panel-default">
		<div class="panel-body">
			<div class="row cl">
				<div class="col-3">&nbsp;</div>
				<div class="col-9">
					<div class="form-group">
				      <label>编码：</label><input type="text" class="text" ng-model="queryData.code" placeholder="请输入编码">
				      <label>分类名称：</label><input type="text" class="text" ng-model="queryData.categoryName" placeholder="请输入分类名称">
				      <label>状态：</label>
				     <select class="text" ng-model="queryData.isUse"
						ng-options="state.id as state.value for state in categoryState">
					</select>
				      <a href="javascript:;" ng-click="query();" class="btn btn-primary radius">
						<i class="Hui-iconfont">&#xe665;</i>查询
					</a>
				   </div>
				</div>
			</div>
		</div>
	</div>

	<div class="mt-20">
		<table class="table table-border table-bordered table-hover table-bg table-sort">
			<thead>
				<tr class="text-c">
					<th style="text-align: center; width: 5%">序号</th>
					<th style="text-align: center; width: 15%">编码</th>
					<th style="text-align: center; width: 20%">分类名称</th>
					<th style="text-align: center; width: 10%">状态</th>
					<th style="text-align: center; width: 15%">添加人</th>
					<th style="text-align: center; width: 15%">日期</th>
					<th style="text-align: center; width: 20%">操作</th>
				</tr>
			</thead>
			<tbody>
				<tr ng-repeat="t in dataList" class="text-c">
					<td>{{$index+1+(paginationConf.currentPage-1)*paginationConf.pageRecord}}</td>
					<td>{{t.code}}</td>
					<td>{{t.categoryName}}</td>
					<td>
						<div ng-show="{{t.isUse==0}}">禁用</div>
						<div ng-show="{{t.isUse==1}}">启用</div>
					</td>
					<td>{{t.userName}}</td>
					<td>{{t.createTime}}</td>
					<td>
						<input type="button" class="btn btn-link btn-xs" value="修改" ng-click="openUpdModal(t);"> 
						<input type="button" class="btn btn-link btn-xs" value="删除" ng-click="del(t);">
					</td>
				</tr>
			</tbody>
		</table>
		<div class="row cl">
			<div class="col-offset-1 col-1" style="text-align: left;margin-top: 5px;">
				<input type="button" class="btn btn-primary" value="添加" ng-click="openAddModal();">
			</div>
			<div class="col-10" style="text-align: right;">
				<pagination-tag conf="paginationConf"></pagination-tag>
			</div>
		</div>

	</div>
	<jsp:include page="category-modify.jsp"/>
	<jsp:include page="../common/confirm.jsp"/>
</body>
</html>